<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="全库唯一码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'puid', validatorRules.puid]" placeholder="请输入全库唯一码"></a-input>
        </a-form-item>
        <a-form-item label="采购方编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'purchasercode', validatorRules.purchasercode]" placeholder="请输入采购方编码"></a-input>
        </a-form-item>
        <a-form-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'datasource', validatorRules.datasource]" placeholder="请输入数据来源"></a-input>
        </a-form-item>
        <a-form-item label="供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'suppliercode', validatorRules.suppliercode]" placeholder="请输入供应商编码"></a-input>
        </a-form-item>
        <a-form-item label="供应商名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'suppliername', validatorRules.suppliername]" placeholder="请输入供应商名称"></a-input>
        </a-form-item>
        <a-form-item label="种类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'subclasscode', validatorRules.subclasscode]" placeholder="请输入种类编码"></a-input>
        </a-form-item>
        <a-form-item label="同步起始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择同步起始时间" v-decorator="[ 'synchronizationdatestart', validatorRules.synchronizationdatestart]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="同步结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择同步结束时间" v-decorator="[ 'synchronizationdateend', validatorRules.synchronizationdateend]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="同步成功数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'successnum', validatorRules.successnum]" placeholder="请输入同步成功数量" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="同步结束数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'failuresnum', validatorRules.failuresnum]" placeholder="请输入同步结束数量" style="width: 100%"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "EipDataSynchronizationInfoModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        puid:{rules: [{ required: true, message: '请输入全库唯一码!' }]},
        purchasercode:{rules: [{ required: true, message: '请输入采购方编码!' }]},
        datasource:{rules: [{ required: true, message: '请输入数据来源!' }]},
        suppliercode:{rules: [{ required: true, message: '请输入供应商编码!' }]},
        suppliername:{rules: [{ required: true, message: '请输入供应商名称!' }]},
        subclasscode:{},
        synchronizationdatestart:{rules: [{ required: true, message: '请输入同步起始时间!' }]},
        synchronizationdateend:{rules: [{ required: true, message: '请输入同步结束时间!' }]},
        successnum:{rules: [{ required: true, message: '请输入同步成功数量!' }]},
        failuresnum:{rules: [{ required: true, message: '请输入同步结束数量!' }]},
        },
        url: {
          add: "/pg/eipDataSynchronizationInfo/add",
          edit: "/pg/eipDataSynchronizationInfo/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'puid','purchasercode','datasource','suppliercode','suppliername','subclasscode','synchronizationdatestart','synchronizationdateend','successnum','failuresnum'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'puid','purchasercode','datasource','suppliercode','suppliername','subclasscode','synchronizationdatestart','synchronizationdateend','successnum','failuresnum'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>